Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In optimizeComponents be sure to also remove components that are defined in the primitive with empty object #780

Merged
merged 2 commits into from
Nov 27, 2024

Conversation

vincentfretin
Copy link
Contributor

In optimizeComponents used by the copy entity to clipboard feature, be sure to also remove components that are defined in the primitive with empty object, for example a-camera here https://github.com/aframevr/aframe/blob/a26768db5fe0f04a3b8fec3e73780b1855c3c75c/src/extras/primitives/primitives/a-camera.js#L5-L7

defaultComponentsFromPrimitive is defined by this.defaultComponentsFromPrimitive = definition.defaultComponents || definition.defaultAttributes || {}; in aframe registerPrimitive. https://github.com/aframevr/aframe/blob/a26768db5fe0f04a3b8fec3e73780b1855c3c75c/src/extras/primitives/primitives.js#L37
defaultComponents is only on the definition, never on the html element, so checking for source.defaultComponents is always undefined from my understanding.
I modified getInjectedValue to check only defaultComponentsFromPrimitive and don't create unnessary object if it's undefined.

Also in getMixedValue, the line source.mixinEls.reverse() was reversing the mixinEls in place, so the order changed on each execution, not really what we want here, I replaced by toReversed()

getImplicitValue didn't return isInherited true in case of empty object in the primitive defaultComponents, so the component wasn't deleted as part of the if (isInherited && doesNotNeedUpdate) check.

if (isInherited && doesNotNeedUpdate) {
removeAttribute.call(copy, name);

I fixed it.

Before:

<a-cursor raycaster cursor></a-cursor>

After:

<a-cursor raycaster></a-cursor>

raycaster is set by the cursor component so that's why it still shows up, but I don't mind, it's good practice to define objects property in raycaster anyway.

Before:

<a-camera camera look-controls wasd-controls>

After:

<a-camera>

@vincentfretin
Copy link
Contributor Author

@dmarcos that's a small part of my work on a better full html export of a-scene I'm currently doing.

@vincentfretin
Copy link
Contributor Author

vincentfretin commented Nov 26, 2024

in controllers.html with the mixin

<a-mixin id="interactable" event-set__mouseenter="_event: mouseenter; material.opacity: 0.75" event-set__mouseleave="_event: mouseleave; material.opacity: 1" event-set__click="_event: click; scale: 1.1 1.1 1.1"></a-mixin>

The entity

        <a-entity id="redBox" mixin="interactable" geometry="primitive: box" material="color: #F00" position="-4 1 0">

was exported to html with

        <a-entity id="redBox" mixin="interactable" geometry="primitive: box" material="color: #F00" position="-4 1 0" event-set__mouseenter="[object Object]" event-set__mouseleave="[object Object]" event-set__click="[object Object]">

event-set__mouseenter, event-set__mouseleave, event-set__click shouldn't be there. Those didn't change from the mixin.
The code was checking component.name that is event-set instead of component.attrName (see https://github.com/aframevr/aframe/blob/a26768db5fe0f04a3b8fec3e73780b1855c3c75c/src/core/component.js#L68) that is the full attribute name event-set__mouseenter.

The serialization to [object Object] is a separate issue.

…vent-set__click when checking for implicit value (from mixin or primitive)
@vincentfretin vincentfretin force-pushed the fix-optimize-components branch from cdc1a89 to 2d1358b Compare November 26, 2024 13:19
@vincentfretin
Copy link
Contributor Author

For the event-set__mouseenter serialization issue, see #781

@dmarcos
Copy link
Member

dmarcos commented Nov 27, 2024

Thank you!

@dmarcos dmarcos merged commit a2aefc8 into aframevr:master Nov 27, 2024
1 check passed
@vincentfretin vincentfretin deleted the fix-optimize-components branch November 28, 2024 08:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants